/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Game;

import Cards.FrenchCard;
import Internationalization.LoadInternationalization;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * Class PlayerBJ. It can use to manage any BlackJack Player. It has a extra hand 
 * @author masterinftel11
 */
public class PlayerBJ extends Player<FrenchCard>{

    private boolean split;
    private ArrayList<FrenchCard> extrahand;    //La mano
    
    /**
     * Method to print to choose option
     */
    public void printoption(char c){
        if(c == 'P'){
            System.out.println(LoadInternationalization.getRB().getString("player") + ": " + id + LoadInternationalization.getRB().getString("plays"));
        }
        else{
            System.out.println(LoadInternationalization.getRB().getString("bot") + ": " + id + LoadInternationalization.getRB().getString("plays"));
        }
        System.out.println(LoadInternationalization.getRB().getString("chooseOption"));
        System.out.println(LoadInternationalization.getRB().getString("stand"));
        System.out.println(LoadInternationalization.getRB().getString("hit"));
    }

    /**
     * Method to print to choose where you like your card
     */
    public void printwhere(){
        System.out.println(LoadInternationalization.getRB().getString("where"));
        System.out.println(LoadInternationalization.getRB().getString("left"));
        System.out.println(LoadInternationalization.getRB().getString("right"));
    }
    
    /**
     * 
     * @param id player
     */
    public PlayerBJ(String id){
        super(id);
        extrahand = new ArrayList<>();
    }
    
    /**
     * This method makes turn of player
     * @param currentGame 
     */
    public void myTurn(BJGame currentGame){
        printoption('P');
        
        Scanner sc = new Scanner(System.in);
        
        switch (sc.nextInt()){
            case 1:
                break;
            case 2:
                int option = 1;
                if(this.getSplit()){
                    printwhere();
                    Scanner sp = new Scanner(System.in);
                    option = sp.nextInt();
                }                
                switch(option){
                    case 1:
                        this.addCardToHand(currentGame.deck.takeCard());
                        currentGame.printstate();
                        if(points() < 21)
                            this.myTurn(currentGame); 
                        break;
                    case 2:
                        this.addCardToExtraHand(currentGame.deck.takeCard());
                        currentGame.printstate();
                        if(extrapoints() < 21)
                            this.myTurn(currentGame);  
                        break;
                    default:
                        System.out.println(LoadInternationalization.getRB().getString("invalidOption"));
                        break;
                }

                break;
            default:
                System.out.println(LoadInternationalization.getRB().getString("invalidOption"));
                break;
        }        
    }
    
    /**
     * This method makes turn of Cupier
     * @param currentGame 
     */
    public void cupierTurn(BJGame currentGame){
        this.addCardToHand(currentGame.deck.takeCard());
        currentGame.printstate();
        if(points() < 17)
            this.cupierTurn(currentGame);
        
    }  
    
    /**
     * This method to get points on current hand
     * @return points
     */
    public int points(){
        int points = 0;
        for(int i=0; i<this.getHand().size(); i++){
            if(this.getHand().get(i).getRank().getCode() == 1 && points > 10)
                points++;
            else
                points += this.getHand().get(i).points();
        }
        return points;
    }
    
    /**
     * This method to get point on extrahand (when you have two hands)
     * @return points
     */
    public int extrapoints(){
        int points = 0;
        for(int i=0; i<this.getExtraHand().size(); i++){
            if(this.getExtraHand().get(i).getRank().getCode() == 1 && points > 10)
                points++;
            else
                points += this.getExtraHand().get(i).points();
        }
        return points;
    }    

    /**
     * Method to get the state of split
     * @return true: if you've had split
     */
    public boolean getSplit(){
        return split;
    }
    
    /**
     * Method to set split
     * @param split 
     */
    public void setSplit(boolean split){
        this.split = split;
    }
    
    /**
     * Method to add card to extra hand
     * @param c card to add to hand
     */
    public void addCardToExtraHand(FrenchCard c){
        extrahand.add(c);
    }    
    
    /**
     * Method to get extra hand (when you split)
     * @return extrahand
     */
    public ArrayList<FrenchCard> getExtraHand(){
        return extrahand;
    }
}
